//
//  MAMaskView.m
//  meiang_edu
//
//  Created by 贾倍 on 2019/1/2.
//  Copyright © 2019 com.meiang.meiang_edu. All rights reserved.
//

#import "MAMaskView.h"
#import "AppDelegate.h"

@implementation MAMaskView

//初始化view以及添加蒙层
-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.frame = frame;
        self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.6];
        self.userInteractionEnabled = YES;
        UITapGestureRecognizer *tapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(removeGes)];
        [self addGestureRecognizer:tapGes];
    }
    return self;
}

//移除蒙层
-(void)removeGes{
    [self removeFromSuperview];
}

//把蒙层添加到window上
+(instancetype)makeViewWithMaskFrame:(CGRect)frame andView:(UIView *)view{
    MAMaskView *maskV = [[ self alloc] initWithFrame:frame];
    AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    [delegate.window addSubview:maskV];
    [maskV addSubview:view];
    return maskV;
}

-(void)block:(void (^)(void))block{
    [self removeFromSuperview];
    block();
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
